package com.example.ucs.util;

import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSON;
import com.example.ucs.dto.UserDTO;
import com.sun.org.apache.bcel.internal.generic.IF_ACMPEQ;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Component;

@Component
public class UserTraceUtil {

    @Autowired
    private StringRedisTemplate stringRedisTemplate;

    public UserDTO getCurrentUserByAccessToken(String accessToken) {
        String tokenKey = "token:" + accessToken;
        if (!stringRedisTemplate.hasKey(tokenKey)) {
            return null;
        }
        if (StrUtil.isBlank(stringRedisTemplate.opsForValue().get(tokenKey))) {
            return null;
        }
        return JSON.parseObject(stringRedisTemplate.opsForValue().get(tokenKey), UserDTO.class);
    }


}
